import { deleteByPrimaryKeyForProUserAuth, selectByPrimaryKeyForProUserAuth, insertForProUserAuth, updateForProUserAuth, deleteByMapForProUserAuth,updateByMapForProUserAuth, getOneForProUserAuth,getAllForProUserAuth,queryPageForProUserAuth, countForProUserAuth, insertBatchForProUserAuth, deleteBatchForProUserAuth,getPageProUserByAuthId,queryPageForProAuthority,queryPageForProUserChild,getSelectedProUserByAuthId } from '@/services/system/api_prouserauth';

export default {
    namespace: 'prouserauth',

    state: {
        data: {
            list: [],
            pagination: {},
        },
        user: {
        	list: [],
          	pagination: {},
        },
        userChild: {
        	list: [],
          	pagination: {},
        },
        userSelect: {
        	list: [],
        }
    },

    effects: {
            *delete_by_primarykey_for_prouserauth({ payload }, { call, put }) {
                const response = yield call(deleteByPrimaryKeyForProUserAuth, payload);
                yield put({
                    type: 'deleteByPrimaryKeyForProUserAuth',
                    payload: response,
                });
            },
            *select_by_primarykey_for_prouserauth({ payload, callback }, { call, put }) {
                const response = yield call(selectByPrimaryKeyForProUserAuth, payload);
                yield put({
                    type: 'selectByPrimaryKeyForProUserAuth',
                    payload: response,
                });
                if (callback) callback();
            },
            *insert_for_prouserauth({ payload, callback }, { call, put }) {
                const response = yield call(insertForProUserAuth, payload);
                yield put({
                    type: 'insertForProUserAuth',
                    payload: response,
                });
                if (callback) callback();
            },
            *update_for_prouserauth({ payload, callback }, { call, put }) {
                const response = yield call(updateForProUserAuth, payload);
                yield put({
                    type: 'updateForProUserAuth',
                    payload: response,
                });
                if (callback) callback();
            },
            *delete_by_map_for_prouserauth({ payload, callback }, { call, put }) {
                const response = yield call(deleteByMapForProUserAuth, payload);
                yield put({
                    type: 'deleteByMapForProUserAuth',
                    payload: response,
                });
                if (callback) callback();
            },
            *update_by_map_for_prouserauth({ payload, callback }, { call, put }) {
                const response = yield call(updateByMapForProUserAuth, payload);
                yield put({
                    type: 'updateByMapForProUserAuth',
                    payload: response,
                });
                if (callback) callback();
            },
            *get_one_for_prouserauth({ payload, callback }, { call, put }) {
                const response = yield call(getOneForProUserAuth, payload);
                yield put({
                    type: 'getOneForProUserAuth',
                    payload: response,
                });
                if (callback) callback();
            },
            *get_all_for_prouserauth({ payload, callback }, { call, put }) {
                const response = yield call(getAllForProUserAuth, payload);
                yield put({
                    type: 'getAllForProUserAuth',
                    payload: response,
                });
                if (callback) callback();
            },
            *query_page_for_prouserauth({ payload, callback }, { call, put }) {
                const response = yield call(queryPageForProUserAuth, payload);
                yield put({
                    type: 'queryPageForProUserAuth',
                    payload: response,
                });
                if (callback) callback();
            },
            *count_for_prouserauth({ payload, callback }, { call, put }) {
                const response = yield call(countForProUserAuth, payload);
                yield put({
                    type: 'countForProUserAuth',
                    payload: response,
                });
                if (callback) callback();
            },
            *insert_batch_for_prouserauth({ payload, callback }, { call, put }) {
                const response = yield call(insertBatchForProUserAuth, payload);
                yield put({
                    type: 'insertBatchForProUserAuth',
                    payload: response,
                });
                
                const responsedata = yield call(queryPageForProAuthority, {});
                yield put({
                	type: 'queryPageForProAuthority',
                	payload: responsedata,
                });
                
                const newPayload = { auth_id: [payload.authids[0].id]};
                const responseUser = yield call(getPageProUserByAuthId, newPayload);
                yield put({
                    type: 'getPageProUserByAuthId',
                    payload: responseUser,
                });
                
                if (callback) callback();
            },
            *delete_batch_for_prouserauth({ payload, callback }, { call, put }) {
                const response = yield call(deleteBatchForProUserAuth, payload);
                yield put({
                    type: 'deleteBatchForProUserAuth',
                    payload: response,
                });
                if (callback) callback();
            },
            *update_batch_for_prouserauth({ payload, callback }, { call, put }) {
                const response = yield call(updateBatchForProUserAuth, payload);
                yield put({
                    type: 'updateBatchForProUserAuth',
                    payload: response,
                });
                if (callback) callback();
            },
            *get_page_prouser_by_authid({ payload, callback }, { call, put }) {
                const response = yield call(getPageProUserByAuthId, payload);
                yield put({
                    type: 'getPageProUserByAuthId',
                    payload: response,
                });
                if (callback) callback();
            },
            *query_page_for_proauthority({ payload, callback }, { call, put }) {
                const response = yield call(queryPageForProAuthority, payload);
                yield put({
                    type: 'queryPageForProAuthority',
                    payload: response,
                });
                if (callback) callback();
            },
            *query_page_for_prouserchild({ payload, callback }, { call, put }) {
                const response = yield call(queryPageForProUserChild, payload);
                yield put({
                    type: 'queryPageForProUserChild',
                    payload: response,
                });
                if (callback) callback();
            },
            *get_selected_prouser_by_authid({ payload, callback }, { call, put }) {
                const response = yield call(getSelectedProUserByAuthId, payload);
                yield put({
                    type: 'getSelectedProUserByAuthId',
                    payload: response,
                });
                if (callback) callback();
            },
            },

    reducers: {
        deleteByPrimaryKeyForProUserAuth(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        selectByPrimaryKeyForProUserAuth(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        insertForProUserAuth(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        updateForProUserAuth(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        deleteByMapForProUserAuth(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        updateByMapForProUserAuth(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        getOneForProUserAuth(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        getAllForProUserAuth(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        queryPageForProUserAuth(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        countForProUserAuth(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        insertBatchForProUserAuth(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        deleteBatchForProUserAuth(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        updateBatchForProUserAuth(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        getPageProUserByAuthId(state, action) {
            return {
                ...state,
                user: action.payload,
            };
        },
        queryPageForProAuthority(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        queryPageForProUserChild(state, action) {
            return {
                ...state,
                userChild: action.payload,
            };
        },
        getSelectedProUserByAuthId(state, action) {
            return {
                ...state,
                userSelect: action.payload,
            };
        },
    },
};
